package org.shopen.ai.puremvc.model.domain.cities
{
	import org.shopen.ai.puremvc.model.IRavisSerializable;
	import org.shopen.ai.puremvc.model.IReadable;
	import org.shopen.ai.puremvc.model.ISerializable;
	import org.shopen.ai.puremvc.model.utils.Convert;

	public class Path implements ISerializable, IRavisSerializable, IReadable
	{
		[Bindable]
		private var _from : int;
		[Bindable]
		public function get from() : int
		{
			return _from;
		}
		public function set from(value : int) : void
		{
			_from = value;
		}
		
		[Bindable]
		private var _dest : int;
		[Bindable]
		public function get dest() : int
		{
			return _dest;
		}
		public function set dest(value : int) : void
		{
			_dest = value;
		}
		
		[Bindable]
		private var _distance : Number = 0;
		[Bindable]
		public function get distance() : Number
		{
			return _distance;
		}
		public function set distance(value : Number) : void
		{
			_distance = value;
		}
		
		public function Path(node : XML = null)
		{
			if (node != null)
			{
				deserialize(node);
			}
		}
		
		public function deserialize(node : XML) : void
		{
			if ("@from" in node)
			{
				this.from = Convert.toInt(node.@from);
			}
			if ("@dest" in node)
			{
				this.dest = Convert.toInt(node.@dest);
			}
			if ("@distance" in node)
			{
				this.distance = Convert.toNumber(node.@distance);
			}
		}
		
		public function serialize() : XML
		{
			// TODO: not yet implemented
			return new XML();
		}
		
		public function toRavisXml() : XML
		{
			var edge : XML = new XML(<Edge />);
			edge.@fromID = this.from;
			edge.@toID = this.dest;
			edge.@distance = this.distance;
			
			return edge;
		}
		
		public function toString() : String
		{
			return this.distance.toString();
		}
	}
}